//mac上调试
//kickstart2018E problem2
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>

using namespace std;
// 如果没有不可选的，就很简单，每个都选代价最小。
// 有了不可选的，感觉这样类似于beam search。不可选最多100，则每次保留101个。

//所以参数范围也要看。（看分数、大小数据集个数、参数范围）
void sort(vector<pair<string, int>>& vec)
{
    for (int i = 0; i < vec.size(); ++i)
    {
        for (int j = i + 1; j < vec.size(); ++j)
        {
            if (vec[j].second < vec[i].second)
            {
                swap(vec[i], vec[j]);
            }
        }
    }
}
int solve(int P, vector<string>& friends, vector<string>& forbidden)
{
    vector<int> cost(P, 0);
    vector<pair<string, int>> results;
    for (int i = 0; i < P; ++i)
    {
        for (int j = 0; j < friends.size(); ++j)
        {
            cost[i] += (friends[j][i] == '1');
        }
    }
    results.push_back(pair<string, int>("", 0));
    for (int i = 0; i < P; ++i)
    {
        vector<pair<string, int>> tmp;
        for (int j = 0; j < results.size(); ++j)
        {
            tmp.push_back(pair<string, int>(results[j].first + '0',
                                            results[j].second + cost[i]));
            tmp.push_back(pair<string, int>(results[j].first + '1',
                                            results[j].second + friends.size() - cost[i]));
        }
        sort(tmp);
        results.assign(tmp.begin(), tmp.begin() + (tmp.size() < 101 ? tmp.size() : 101));
        // c++会越界！不要像python一样用
    }
    for (auto r: results)
    {
        if (find(forbidden.begin(), forbidden.end(),
                 r.first) == forbidden.end()) // !=和== 别搞反了！
        {
            return r.second;
        }
    }
    return 0;
}
int main()
{
    int T;
    cin >> T;
    for (int ti = 1; ti <= T; ++ti)
    {
        int N, M, P;
        cin >> N >> M >> P;
        vector<string> friends;
        for (int i = 0; i < N; ++i)
        {
            string tmp;
            cin >> tmp;
            friends.push_back(tmp);
        }
        vector<string> forbidden;
        for (int i = 0; i < M; ++i)
        {
            string tmp;
            cin >> tmp;
            forbidden.push_back(tmp);
        }
        int res = solve(P, friends, forbidden);
        cout << "Case #" << ti << ": " << res << endl;
    }
    return 0;
}
